<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * This is the key class to all the admin panel functionality.
    * It is extended into child classes which do all the work.
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 22.04.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    
    /***
    * Abstract Class adminModule
    ****
    * Main purpose of this class is to handle all the template logic
    * any part of the admin panel may have. Moreover, this class is
    * responsible for the display of any child classes templates and
    * results. In other words, anything that reaches the browser
    * goes through this class!
    * 
    * This is an abstract class, meaning it has to be extended to add
    * the neccessary functionality. Base methods have already been
    * implemented and finalized.
    ****
    * @package adminModules
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 28.07.2005
    * @copyright essentialmind.com 2005
    ***/
    abstract class adminModule{
    
        /**
         * Reference to the database connection object
         *
         * @var ADOConnection
         */
        protected $db;
        
        /**
         * reference to the template parser
         *
         * @var mySmarty
         */
        protected $smarty;
        
        /**
         * name of the template on which the extension will be based on
         *
         * @var string
         */
        protected $action;
        
        /**
         * reference to the log object
         *
         * @var object
         */
        protected $log;
        
        
        /* ------------- END VARIABLE DECLARATION --------------- */
        

        /**
         * @param object $db     - Reference to the ADODB Connection
         * @param object $smarty - Reference to Smarty
         * @return void
         **/
        function __construct(ADOConnection $db, mySmarty $smarty, $log){
            $this->db       = $db;
            $this->smarty   = $smarty;
            $this->log      = $log;
        }
        

        /**
         * Method signature. Forces the child class to implement
         * this method, which will set the HTML template needed for
         * the child's operation
         * 
         * @return 
         **/
        abstract protected function setTemplate();
        
        
        /**
         * Method Signature. Forces the child class to implement
         * a data processor.
         * 
         * @return 
         **/
        abstract protected function process();

        
        /**
         * Sets the name of an action template
         * 
         * @param string $action - Name of the action template to be used
         * @return void
         **/
        final function setActionTemplate($action){
            $this->action = $action;
        }


        /**
         * adminModule::getActionTemplate()
         * 
         * Returs the name of the currently set action template
         * 
         * @return string
         **/
        final function getActionTemplate(){
            return $this->action;
        }


        /**
         * Outputs the module to the screen
         * 
         * @param string $template - name of base template
         * @return 
         **/
        final function display($template='index.html'){
            //set the child's action template
            $this->setTemplate();

            //check if the action space exists
            if(!$this->smarty->template_exists($this->getActionTemplate())){
                throw new Exception('The defined action template "'.$this->getActionTemplate().'" does not exist!',4);
            }

            //all went fine, thus assign the action template to smarty
            $this->smarty->assign('action',$this->getActionTemplate());
            
            //and also get the navigation tabs for the current user

            $this->smarty->assign('tabs',$_SESSION['admin']['permissions']); 
            
            //run the class' data processor and
            //process actions, such as GET and POST requests
            $this->process();
            
            //error check is done, lets do the template magic!
            $this->smarty->display($template);
        }
    }
?>